cd "~/Dropbox/Shared Folder - J. Ladd & M (1). Meredith/Replication Files/"
cap log close
log using "LogFiles/TableA17.log", replace

clear all
set more off

matrix Results = J(33, 9, -9)

use "RawData/GallupDataBJPS.dta", clear

// Drops Unrepresentative Series
drop if drops == "All" | regexm(drops, "Party")
// Drops Obs. w/o Gender
drop if female < 0
// Drops Obs. w/o Weights
drop if final_weight < 0
// Drops Obs. w/o Dem., Ind., or Rep.
keep if party == -1 | party == 0 | party == 1
// Keeps In-Person Surveys
keep if survey == 1

// Sets the Survey Date as the Mid-Point in Field
gen middle_date = .
replace middle_date = floor((start_date + end_date) / 2)
sort middle_date
format middle_date %td
gen year = year(middle_date)  

// Codes Dem. as 0, Ind. as 1/2, and Rep. as 1
// Partisan 1 = Leaners Ind, Partisan 2 = Leaners as Partisans
gen partisan = 0 if party == -1
replace partisan = 1 if party == 1
replace partisan = .5 if party == 0

save "ProcessedData/temp.dta", replace

// Region
use "ProcessedData/temp.dta", clear
drop if state < 0
gen neweng = (state >= 11 & state <= 16)
gen midatl = (state >= 21 & state <= 27)
gen midwst = (state >= 31 & state <= 48)
gen south = (state >= 51 & state <= 65)
gen rockymt = (state >= 71 & state <= 78)
gen west = (state >= 81 & state <= 85)
foreach var of varlist neweng-west {
gen femaleX`var' = female * `var'
}
forvalues i = 1953(4)1993 {
local j = 1 + 3*(`i' - 1953)/4
cap areg partisan midatl-femaleXwest [aweight = final_weight] /*
*/ if year >= `i' & year <= `i' + 3, absorb(series) robust
local temp = _rc
if `temp' == 0 {
mat Results[`j', 1] = _b[femaleXneweng]
mat Results[`j' + 1, 1] = -_se[femaleXneweng]
cap count if neweng == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 1] = r(N)
mat Results[`j', 2] = _b[femaleXmidatl]
mat Results[`j' + 1, 2] = -_se[femaleXmidatl]
cap count if midatl == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 2] = r(N)
mat Results[`j', 3] = _b[femaleXmidwst]
mat Results[`j' + 1, 3] = -_se[femaleXmidwst]
cap count if midwst == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 3] = r(N)
mat Results[`j', 4] = _b[femaleXsouth]
mat Results[`j' + 1, 4] = -_se[femaleXsouth]
cap count if south == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 4] = r(N)
mat Results[`j', 5] = _b[femaleXrockymt]
mat Results[`j' + 1, 5] = -_se[femaleXrockymt]
cap count if rockymt == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 5] = r(N)
mat Results[`j', 6] = _b[femaleXwest]
mat Results[`j' + 1, 6] = -_se[femaleXwest]
cap count if west == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 6] = r(N)
}
}

// City Size
use "ProcessedData/temp.dta", clear
drop if lower_bound_citysize < 0
gen low = (upper_bound_citysize <= 10000 & near100k ~= 1)
gen mid = (upper_bound_citysize > 10000 & upper_bound_citysize <= 100000 & near100k ~= 1)
gen high = (upper_bound_citysize > 100000 | upper_bound_citysize == -1 | near100k == 1)
foreach var of varlist low-high {
gen femaleX`var' = female * `var'
}
forvalues i = 1953(4)1993 {
local j = 1 + 3*(`i' - 1953)/4
cap areg partisan mid-femaleXhigh [aweight = final_weight] /*
*/ if year >= `i' & year <= `i' + 3, absorb(series) robust
local temp = _rc
if `temp' == 0 {
mat Results[`j', 7] = _b[femaleXlow]
mat Results[`j' + 1, 7] = -_se[femaleXlow]
cap count if low == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 7] = r(N)
mat Results[`j', 8] = _b[femaleXmid]
mat Results[`j' + 1, 8] = -_se[femaleXmid]
cap count if mid == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 8] = r(N)
mat Results[`j', 9] = _b[femaleXhigh]
mat Results[`j' + 1, 9] = -_se[femaleXhigh]
cap count if high == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 9] = r(N)
}
}

matlist Results

log close
